from celery import Celery
from django.conf import settings
import os

# 设置Celery的环境变量 worker 进程独立于Django启动

# 需要以来django的配置文件
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "p9_exe.settings")

# 初始化celery对象
app = Celery("worker")
app.conf.broker_url = "redis://:123@127.0.0.1:6379/1"
app.conf.result_backend = "redis://:123@127.0.0.1:6379/2"

# 自动发现任务函数
app.autodiscover_tasks(settings.INSTALLED_APPS)

# celery -A utils.celery_task worker --loglevel=info -P eventlet
# linux
# celery -A utils.celery_task worker -l info
